package com.example.xrecyclerview;

import android.os.Handler;
import android.view.MenuItem;

import java.util.ArrayList;
import java.util.List;

public class LinearActivity extends BaseListActivity {

    private int times = 0;


    @Override
    protected BaseAdapter bindAdapter() {
        return new BaseTestAdapter(this);
    }

    @Override
    protected void onListRefresh() {
        //refreshTime ++;
        //times = 0;
        new Handler().postDelayed(new Runnable(){
            public void run() {
                List<String> tmp=new ArrayList<String>();
                if (times!=0){
                    for(int i = 0; i < 10 ;i++){
                        tmp.add("item" + i + "after " + mRecyclerView.getCurrentPage() + " times of refresh");
                    }
                }

                mAdapter.updataData(mRecyclerView,tmp);
                times ++;
            }

        }, 1000);            //refresh data here
    }

    @Override
    protected void onListLoadMore() {
        if(times < 1){
            new Handler().postDelayed(new Runnable(){
                public void run() {
                    List<String> tmp=new ArrayList<String>();
                    for(int i = 10; i < 20 ;i++){
                        tmp.add("item" + i + "after " + mRecyclerView.getCurrentPage() + " times of refresh");
                    }

                    mAdapter.updataData(mRecyclerView,tmp);
                }
            }, 1000);
        } else {
            new Handler().postDelayed(new Runnable() {
                public void run() {
                    List<String> tmp=new ArrayList<String>();
                    for(int i = 20; i < 25 ;i++){
                        tmp.add("item" + i + "after " + mRecyclerView.getCurrentPage() + " times of refresh");
                    }

                    mAdapter.updataData(mRecyclerView,tmp);
                    mAdapter.updateOneItem(1,"呀呀呀呀呀呀");
                }
            }, 1000);
        }
        times ++;
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
